package com.ruoyi.energy.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.energy.domain.TcPark;
import com.ruoyi.energy.service.ITcParkService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 停车场Controller
 *
 * @author cjie
 * @date 2021-11-30
 */
@Api(tags = " 停车场")
@RestController
@RequestMapping("/tcPark")
public class TcParkController extends BaseController {
    @Autowired
    private ITcParkService tcParkService;

    /**
     * 查询停车场列表
     */
    @ApiOperation(value="查询停车场列表", notes="查询停车场列表")
    @PreAuthorize(hasPermi = "energy:tcPark:list")
    @GetMapping("/list")
    public TableDataInfo list(TcPark tcPark) {
        startPage();
        List<TcPark> list = tcParkService.selectTcParkList(tcPark);
        return getDataTable(list);
    }

    /**
     * 导出停车场列表
     */
    @ApiOperation(value="导出停车场列表", notes="导出停车场列表")
    @PreAuthorize(hasPermi = "energy:tcPark:export")
    @Log(title = "停车场", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcPark tcPark) throws IOException {
        List<TcPark> list = tcParkService.selectTcParkList(tcPark);
        ExcelUtil<TcPark> util = new ExcelUtil<TcPark>(TcPark.class);
        util.exportExcel(response, list, "停车场数据");
    }
    /**
     * 获取停车场详细信息
     */
    @ApiOperation(value="获取停车场详细信息", notes="获取停车场详细信息")
    @PreAuthorize(hasPermi = "energy:tcPark:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tcParkService.selectTcParkById(id));
    }

    /**
     * 获取停车场详细信息
     */
    @ApiOperation(value="获取停车场详细信息", notes="获取停车场详细信息")
    @PreAuthorize(hasPermi = "energy:tcPark:query")
    @GetMapping(value = "/setPush/{id}")
    public AjaxResult setPush(@PathVariable("id") Long id) {
        return tcParkService.setPush(id);
    }




    /**
     * 新增停车场
     */
    @ApiOperation(value="新增停车场", notes="新增停车场")
    @PreAuthorize(hasPermi = "energy:tcPark:add")
    @Log(title = "停车场", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcPark tcPark) {
        return toAjax(tcParkService.insertTcPark(tcPark));
    }

    /**
     * 修改停车场
     */
    @ApiOperation(value="修改停车场", notes="修改停车场")
    @PreAuthorize(hasPermi = "energy:tcPark:edit")
    @Log(title = "停车场", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcPark tcPark) {
        return toAjax(tcParkService.updateTcPark(tcPark));
    }

    /**
     * 删除停车场
     */
    @ApiOperation(value="删除停车场", notes="删除停车场")
    @ApiImplicitParam(name = "ids", value = "停车场ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:tcPark:remove")
    @Log(title = "停车场", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tcParkService.deleteTcParkByIds(ids));
    }
}
